//
//  MyheaderView.swift
//  demo01
//
//  Created by babybus on 2025/6/24.
//
import Foundation	
import UIKit
import SnapKit


class MyHeaderView: UICollectionReusableView {
    // 1. 添加titleLabel
    private let titleLabel = UILabel()
    
    // 2. 添加title属性（可选方案）
    var title: String? {
        didSet {
            titleLabel.text = title
        }
    }
    
    // 3. 初始化方法
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // 4. 设置UI
    private func setupUI() {
        titleLabel.textAlignment = .left
        titleLabel.frame = bounds
        addSubview(titleLabel)
        backgroundColor = .white
        titleLabel.snp.makeConstraints{make in
            make.left.equalToSuperview().inset(15)
            make.top.equalToSuperview().inset(10)
        }
        
    }
    
    // 5. 或者使用配置方法（替代方案）
    func setTitle(_ text: String) {
        titleLabel.text = text
    }
}
